package com.example.utils;

import com.example.model.DateMessage;
import com.example.service.IDateMessageService;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author LEI
 * Created by LEI on 2020/3/18.
 */
public class PeriodUtils {

    /**获取该群该用户当天的活动范围
     *
     * @param dateMessageService
     * @param start
     * @param end
     * @param fromGroup
     * @param fromQQ
     * @return
     */
    public static String period(IDateMessageService dateMessageService,Date start, Date end,Long fromGroup, Long fromQQ){
        String time = "";
        int temp = -1;
        Map<String,String[]> dates = DateUtils.dates;
        Iterator<String> iterator = dates.keySet().iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            String[] date = dates.get(key);
            List<DateMessage> dateMessages = dateMessageService.queryPeriod(start, end, date[0], date[1], fromGroup, fromQQ);
            if(dateMessages != null && dateMessages.size() >0){
                if(temp==-1){
                    time = key;
                    temp = dateMessages.size();
                }else {
                    if(dateMessages.size() > temp){
                        time = key;
                        temp = dateMessages.size();
                    }
                }
            }
        }
        return time;
    }
}
